<template>
  <el-dialog
    title="请输入药品排行相关信息"
    :visible.sync="dialogVisible"
    width="30%"
    :before-close="handleClose"
  >
    <!-- 内容 -->
    <el-form
      :model="ruleData"
      :rules="rules"
      ref="ruleData"
      label-width="100px"
    >
      <el-form-item label="请输入编号" prop="queque" width="100">
        <el-input v-model="ruleData.queque"></el-input>
      </el-form-item>
      <el-form-item label="药品名称" prop="name">
        <!-- 0: "兰索拉唑肠溶片",
        1: "甲钴胺片",
        2: "复方求唑沙宗胶囊",
        3: "对乙酰氨基酚片",
        4: "双嘧达膜片",
        5: "阿莫西林胶囊",
        6: "骨肽注射液",
        7: "双氯扽双那肠溶片",
        8: "滴眼用利福平",
        9: "红霉素眼膏", -->
        <el-select v-model="ruleData.name" placeholder="请输入药品名称">
          <el-option label="兰索拉唑肠溶片" :value="0"></el-option>
          <el-option label="甲钴胺片" :value="1"></el-option>
          <el-option label="复方求唑沙宗胶囊" :value="2"></el-option>
          <el-option label="对乙酰氨基酚片" :value="3"></el-option>
          <el-option label="双嘧达膜片" :value="4"></el-option>
          <el-option label="阿莫西林胶囊" :value="5"></el-option>
          <el-option label="骨肽注射液" :value="6"></el-option>
          <el-option label="双氯扽双那肠溶片" :value="7"></el-option>
          <el-option label="滴眼用利福平" :value="8"></el-option>
          <el-option label="红霉素眼膏" :value="9"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="$parent.isDrug = false">取 消</el-button>
      <el-button type="primary" @click="submitForm('ruleData')"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>

<script>
import {addfun} from '../../../api/drug'
export default {
  data() {
    return {
      dialogVisible: true, //控制弹框显示或者隐藏
      ruleData: {
        queque: "",
        name: "",
      },
      rules: {
        queque: [
          { required: true, message: "请输入药品编号", trigger: "blur" },
          {
            min: 3,
            max: 10,
            message: "长度在 3 到 10 个字符",
            trigger: "blur",
          },
        ],
        name: [
          { required: true, message: "请选择药品名称", trigger: "blur" },
        ],
      },
    };
  },
  methods: {   
     submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("排行药品提交成功");
          addfun(this.ruleData).then(res=>{
          if(res.code==200){
            this.$parent.getRanke()//刷新表格
             this.$parent.isDrug = false;//关闭弹框
          }
          });
        } else {
          alert('提交失败')
          return false;
        }
      });
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
          this.$parent.isDrug = false;
        })
        .catch((_) => {});
    },

  
  },
};
</script>

<style></style>
